<?php

/**
 * searchresult actions.
 *
 * @package    Redsea20
 * @subpackage Profile
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class searchresultActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $str="";
      if ($this->getRequestParameter('search')!=null && $this->getRequestParameter('search')!="")
      {
          
          $str=$this->getRequestParameter('search');
          $this->researchs=Doctrine_Query::create()
                  ->from('observationdepthdetail odd')
		  ->leftJoin('odd.Observationdepth od')
		  ->leftJoin('od.Observationdepthattribute oda')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('o.Research r')
                  ->leftJoin('r.Researcher rr')
                  ->leftJoin('odd.Species s')
                  ->leftJoin('s.Unit u')
                  ->leftJoin('s.Tags t')
                  ->leftJoin('od.Unit od_u')
                  ->leftJoin('oda.Attribute at')
                  ->leftJoin('oda.Unit oda_u')
                  ->where('s.species LIKE ?', '%'.$str.'%')
                  ->ORwhere('t.tag LIKE ?', '%'.$str.'%')
                  ->ORwhere('u.unit LIKE ?', '%'.$str.'%')
                  ->ORwhere('r.title LIKE ?', '%'.$str.'%')
                  ->ORwhere('o.location LIKE ?', '%'.$str.'%')
                  ->ORwhere('rr.Firstname LIKE ?', '%'.$str.'%')
                  ->ORwhere('rr.Lastname LIKE ?', '%'.$str.'%')
                  ->ORwhere('at.attributename LIKE ?', '%'.$str.'%')
                  ->ORwhere('oda.attributevalue LIKE ?', '%'.$str.'%')
                  ->ORwhere('od_u.unit LIKE ?', '%'.$str.'%')
                  ->ORwhere('oda_u.unit LIKE ?', '%'.$str.'%')
                  ->ORwhere('substr((cast(o.observationdate as char(800))),1,10) LIKE ?', '%'.$str.'%')
                  ->orderby('o.Location,s.species')
                  ->execute();

      }
    
		  //return sfView::NONE;
  }
  
public function executeHistory(sfWebRequest $request)
  {
    $str="";
      if ($this->getRequestParameter('searchhistory')!=null && $this->getRequestParameter('searchhistory')!="")
      {

          $str=$this->getRequestParameter('searchhistory');

          $this->researchs=Doctrine_Query::create()
                  ->from('observationdepthdetail odd')
		  ->leftJoin('odd.Observationdepth od')
		  ->leftJoin('od.Observationdepthattribute oda')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('o.Research r')
                  ->leftJoin('r.Researcher rr')
                  ->leftJoin('odd.Species s')
                  ->leftJoin('s.Unit u')
                  ->leftJoin('s.Tags t')
                  ->leftJoin('od.Unit od_u')
                  ->leftJoin('oda.Attribute at')
                  ->leftJoin('oda.Unit oda_u')
                  ->where('odd.id In ('.$str.')')
                  ->orderby('o.Location,s.species')
                  ->execute();
      }





		  //return sfView::NONE;
  }

  public function executeAutocomplete(sfWebRequest $request)
  {
    

    
          $researchs=Doctrine_Query::create()
                  ->select('s.id,s.Species')
                  ->from('Species s')
                  ->leftJoin('s.Observationdepthdetail odd')
                  ->orderby('s.species')
                  ->execute();
          $str="";
                   foreach($researchs as $r)
                   {
                    $str=$str.$r->getSpecies()."###";
                   }
                    echo $str;

		  return sfView::NONE;
  }


  public function executeExcelData(sfWebRequest $request)
  {
    $str="";
      if ($this->getRequestParameter('search')!=null && $this->getRequestParameter('search')!="")
      {

          $str=$this->getRequestParameter('search');

          $this->researchs=Doctrine_Query::create()
                  ->from('observationdepthdetail odd')
		  ->leftJoin('odd.Observationdepth od')
		  ->leftJoin('od.Observationdepthattribute oda')
                  ->leftJoin('od.Observation o')
                  ->leftJoin('o.Research r')
                  ->leftJoin('r.Researcher rr')
                  ->leftJoin('odd.Species s')
                  ->leftJoin('s.Unit u')
                  ->leftJoin('s.Tags t')
                  ->leftJoin('od.Unit od_u')
                  ->leftJoin('oda.Attribute at')
                  ->leftJoin('oda.Unit oda_u')
                  ->where('odd.id In ('.$str.')')
                  ->orderby('o.Location,s.species')
                  ->execute();
      }






  }





    
 }